package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.*;

import bean.User;
import dao.UserDao;

public class RegistServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		 doPost(request,response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		 User user=new User();
		 UserDao dao=new UserDao();
		 request.setCharacterEncoding("UTF-8");
		 String userName=(String)request.getParameter("userName");
	     String password2=(String)request.getParameter("password2");
	     String role=(String)request.getParameter("companyName");
	     String safeProblem=(String)request.getParameter("D1");
	     String safeAnswer=(String)request.getParameter("safeAnswer");
	     String hint=request.getParameter("hint");
	     String email=(String)request.getParameter("email");
	  
	    	    	user.setUserName(userName);
	    	    	user.setPassWord(password2);
                    user.setRole(role);
                    user.setSafeProbelm(safeProblem);
                    user.setSafeAnswer(safeAnswer);
                    user.setHint(hint);
                    user.setEmail(email);
                    dao.regist(user);
                  	    	    	
	    	    	request.setAttribute("", "恭喜您注册成功");
       			    request.getRequestDispatcher("login.jsp").forward(request,response);
	    	    }
	     }

